<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
  <head>
  <title>Calculator Sample</title>
  
  <script type="text/javascript" src="formfaces.js"></script>
  
  <xf:model>
  <xf:instance>
  <person>
    <fname/>
    <lname/>
  </person>
  </xf:instance>
  <xf:submission id="form1" method="get"
   action="submit.asp"/>
</xf:model>
  </head>

  <body>

	<xf:input ref="fname">
<xf:label>First Name</xf:label></xf:input><br />

<xf:input ref="lname">
<xf:label>Last Name</xf:label></xf:input><br /><br />

<xf:submit submission="form1">
<xf:label>Submit</xf:label></xf:submit>

    <p>A simple calculator</p>
    <table border="1">
      <tr>
        <td align="right" colspan="6">
          <xf:output ref="/equation/screen"/>

        </td>
      </tr>
      <tr>
        <td>
          <xf:output ref="/equation/memory"><xf:label>M:</xf:label></xf:output>
        </td>
        <td>
        </td>

        <td>
        </td>
        <td>
        </td>
        <td colspan="2">
          <xf:trigger>
            <xf:label>Clear</xf:label>
            <xf:action ev:event="DOMActivate">

              <xf:setvalue ref="/equation/first" value="0"/>
              <xf:setvalue ref="/equation/second" value="0"/>
              <xf:setvalue ref="/equation/result" value="0"/>
              <xf:setvalue ref="/equation/screen" value="0"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>
	      <xf:toggle ev:event="DOMActivate" case="add"/>
            </xf:action>
          </xf:trigger>
        </td>

      </tr>
      <tr>
        <td>
          <xf:trigger>
            <xf:label>MC</xf:label>
            <xf:action ev:event="DOMActivate">	
            <xf:setvalue ref="/equation/memory" value="0"/>
            </xf:action>
          </xf:trigger>

        </td>
        <td>
          <xf:trigger>
            <xf:label>7</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 7"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>

          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>8</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 8"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>

            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>9</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 9"/>

              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>/</xf:label>
            <xf:action ev:event="DOMActivate">

              <xf:setvalue ref="/equation/first" value="/equation/screen"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>
	      <xf:toggle ev:event="DOMActivate" case="divide"/>
            </xf:action>
          </xf:trigger>
        </td>
        <td>
        </td>
      </tr>

      <tr>
        <td>
          <xf:trigger>
            <xf:label>MR</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/memory"/>
              <xf:setvalue ref="/equation/screen" value="/equation/memory"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>

            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>4</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 4"/>

              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>5</xf:label>
            <xf:action ev:event="DOMActivate">

              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 5"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>
          </xf:trigger>
        </td>
	<td>
          <xf:trigger>
            <xf:label>6</xf:label>

            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 6"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>
          </xf:trigger>
        </td>
	<td>
          <xf:trigger>
            <xf:label>*</xf:label>

            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/first" value="/equation/screen"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>
	      <xf:toggle ev:event="DOMActivate" case="multiply"/>
            </xf:action>
          </xf:trigger>
        </td>
      </tr>
      <tr>

        <td>
          <xf:trigger>
            <xf:label>MS</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/memory" value="/equation/screen"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>
            </xf:action>
          </xf:trigger>

        </td>
        <td>
          <xf:trigger>
            <xf:label>1</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 1"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>

          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>2</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 2"/>
              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>

            </xf:action>
          </xf:trigger>
       </td>
       <td>
          <xf:trigger>
            <xf:label>3</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10 + 3"/>

              <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>-</xf:label>
            <xf:action ev:event="DOMActivate">

              <xf:setvalue ref="/equation/first" value="/equation/screen"/>
              <xf:setvalue ref="/equation/screenbuffer" value="0"/>
	      <xf:toggle ev:event="DOMActivate" case="subtract"/>
            </xf:action>
          </xf:trigger>
        </td>
        <td>
          <xf:trigger>
            <xf:label>1/x</xf:label>

            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/screen" value="1 div /equation/screen"/>
            </xf:action>
          </xf:trigger>
        </td>
      </tr>
        <tr>
          <td>
            <xf:trigger>

              <xf:label>M+</xf:label>
              <xf:action ev:event="DOMActivate">
          <xf:setvalue ref="/equation/memory" value="/equation/memory + /equation/screen"/>
          <xf:setvalue ref="/equation/screenbuffer" value="0"/>
        </xf:action>
      </xf:trigger>
      </td>
      <td>

      <xf:trigger>
        <xf:label>0</xf:label>
        <xf:action ev:event="DOMActivate">
          <xf:setvalue ref="/equation/screenbuffer" value="/equation/screenbuffer * 10"/>
          <xf:setvalue ref="/equation/screen" value="/equation/screenbuffer"/>
        </xf:action>
      </xf:trigger>
      </td>

      <td>
      <xf:trigger>
        <xf:label>+/-</xf:label>
        <xf:action ev:event="DOMActivate">
          <xf:setvalue ref="/equation/screen" value="/equation/screen * -1"/>
        </xf:action>
      </xf:trigger>
      </td>

      <td>
      </td>
      <td>
      <xf:trigger>
        <xf:label>+</xf:label>
        <xf:action ev:event="DOMActivate">
          <xf:setvalue ref="/equation/first" value="/equation/screen"/>
          <xf:setvalue ref="/equation/screenbuffer" value="0"/>

	  <xf:toggle ev:event="DOMActivate" case="add"/>
        </xf:action>
      </xf:trigger>
      </td>
      <td>
      <xf:switch>
        <xf:case id="add" selected="true">
          <xf:trigger>
            <xf:label>=</xf:label>

            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/second" value="/equation/screenbuffer"/>
              <xf:setvalue ref="/equation/result" value="/equation/first + /equation/second"/>
            <xf:setvalue ref="/equation/screen" value="/equation/result"/>
            <xf:setvalue ref="/equation/screenbuffer" value="0"/>
            </xf:action>
          </xf:trigger>
	</xf:case>
        <xf:case id="subtract">

          <xf:trigger>
            <xf:label>=</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/second" value="/equation/screenbuffer"/>
              <xf:setvalue ref="/equation/result" value="/equation/first - /equation/second"/>
            <xf:setvalue ref="/equation/screen" value="/equation/result"/>
            <xf:setvalue ref="/equation/screenbuffer" value="0"/>
            </xf:action>

          </xf:trigger>
	</xf:case>
        <xf:case id="multiply">
          <xf:trigger>
            <xf:label>=</xf:label>
            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/second" value="/equation/screenbuffer"/>
              <xf:setvalue ref="/equation/result" value="/equation/first * /equation/second"/>

            <xf:setvalue ref="/equation/screen" value="/equation/result"/>
            <xf:setvalue ref="/equation/screenbuffer" value="0"/>
            </xf:action>
          </xf:trigger>
	</xf:case>
        <xf:case id="divide">
          <xf:trigger>
            <xf:label>=</xf:label>

            <xf:action ev:event="DOMActivate">
              <xf:setvalue ref="/equation/second" value="/equation/screenbuffer"/>
              <xf:setvalue ref="/equation/result" value="/equation/first div /equation/second"/>
            <xf:setvalue ref="/equation/screen" value="/equation/result"/>
            <xf:setvalue ref="/equation/screenbuffer" value="0"/>
            </xf:action>
          </xf:trigger>
	</xf:case>
      </xf:switch>

     </td>
      </tr>
      </table>


  </body>
</html>
